package org.example.learn.bytebuddy;

import net.bytebuddy.ByteBuddy;
import net.bytebuddy.implementation.FixedValue;

import static net.bytebuddy.matcher.ElementMatchers.named;

public class HelloWorld {

    public static void main(String[] args) throws IllegalAccessException, InstantiationException {
        String val = new ByteBuddy()
                //设置父类
                .subclass(Object.class)
                //获取目标方法名
                .method(named("toString"))
                //拦截添加参数信息
                .intercept(FixedValue.value("Hello world"))
                //创建
                .make()
                //加载目标类
                .load(HelloWorld.class.getClassLoader())
                //获取已经加载完毕的类
                .getLoaded()
                //创建对象
                .newInstance()
                //调用方法 被修改的方法
                .toString();
        System.out.println(val);
    }
}
